package it.learn.kafka.producer81.listener;

import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import com.alibaba.cloud.nacos.registry.NacosRegistration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.net.URI;

// 服务预注册事件
@Slf4j
@Component
public class InstancePreRegisteredEventListener implements ApplicationListener<InstancePreRegisteredEvent> {

    @Override
    public void onApplicationEvent(InstancePreRegisteredEvent event) {
        log.warn("开始处理，服务预注册事件......");
        NacosRegistration registration = (NacosRegistration) event.getRegistration();

        URI uri = registration.getUri();
        System.out.println("uri.toString() = " + uri.toString());

        NacosAutoServiceRegistration serviceRegistration = (NacosAutoServiceRegistration) event.getSource();

        System.out.println("serviceRegistration.toString() = " + serviceRegistration.toString());

    }

}
